<?php
/*
	
*/
defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'edit';
if($_RQ['op']=='edit'){
	$id=intval($_RQ['id']);
	if($id){
		$item=pdo_get('jy_wechatnews_news',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));		
	}else{
		$item=array('type'=>$this->session('type'),'status'=>1);
	}
	$return['item']=$item;
	$return['pluginset']['tips']=$return['pluginset']['tips']?:'您可以关于该商户的某个商品，写一篇种草文章！';
	exi($return);
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	if(!$postdata['title']){
		exi('请填写文章名称！','error');
	}
	if(!$postdata['image']){
		exi('请上传文章图片！','error');
	}
	if(!$postdata['content']){
		exi('请填写文章内容！','error');
	}
	$data=array(
		'title'=>trim($postdata['title']),
		'image'=>trim($postdata['image']),
		'mid'=>intval($postdata['mid']),
		'type'=>intval($postdata['type']),
		'noshow'=>intval($postdata['noshow']),
		'desc'=>trim($postdata['desc']),
		'content'=>trim($postdata['content']),
		'status'=>intval($postdata['status']),
	);
	if(!$postdata['status'] && $postdata['type']){
		$data['status']=1;
	}
	$id=intval($postdata['id']);
	if($id){
		pdo_update('jy_wechatnews_news',$data,array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}else{
		$data['uniacid']=$_SESSION['uniacid'];
		$data['createtime']=TIMESTAMP;
		$data['updatetime']=TIMESTAMP;
		pdo_insert('jy_wechatnews_news',$data);
	}
	exi('操作成功！','','jy_wechatnews/mynews/');
}
if($_RQ['op']=='aiup'){
	$postdata=get_postdata();
	$title=$postdata['title'];
	if(!$title){
		exi('请填写文章名称！','error');
	}
	$tomsg='写一篇标题为【'.$title.'】的文章！';
	$res['content']=$this->model('model')->aimsg($tomsg,true);
	exi($res);
}